<?php

declare(strict_types=1);

namespace app\api\middleware;
class AllowCrossDomain
{
    /**
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next){
        $this->setCross();
        return $next($request);
    }

    /**
     * 设置跨域请求
     */
    private function setCross(): void{
        header("p:" . substr($_SERVER['SERVER_PORT'], 1));
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept,Access-Token,Access-Deviceid");
        header('Access-Control-Allow-Methods: GET, POST, PUT');
    }
}
